export default class AppError extends Error {
  #code: number;

  constructor(code: number, message: string) {
    super(message);
    this.#code = code;
  }

  get code(): number {
    return this.#code;
  }

  /**
   * Create a not login error.
   *
   * @param message error message
   * @returns a not login error
   */
  static unauthenticated(message = "Unauthenticated"): AppError {
    return new AppError(401, message);
  }

  /**
   * Create a without permission error.
   *
   * @param message error message
   * @returns a without permission error
   */
  static unauthorized(message = "Unauthorized"): AppError {
    return new AppError(403, message);
  }

  /**
   * Create a bad request error.
   * @param message  error message
   * @returns a bad request error
   */
  static badRequest(message = "Bad request"): AppError {
    return new AppError(400, message);
  }
}
